/**
 * Created by yoyoyk on 2017/7/13.
 */
import {type} from 'fly';

export function dateFormat(d){
    if(!d || type(d) !== "date"){ return; };

    const date = new Date(d);

    let curDate = date.toLocaleDateString().replace(/\//g,"-").split("-");

    if(curDate[1].length===1){
        curDate[1] = "0" + curDate[1];
    }

    if(curDate[2].length===1){
        curDate[2] = "0" + curDate[2];
    }

    // debugger
    return curDate.join("-");
}

/***
 * @param startDate ?: string ["2017-02-05"]
 * @param endDate ?: string  ["2017-02-18"]
 * **/
export function differenceDate (startDate,endDate){
    let start = new Date(startDate);
    let end = new Date(endDate);
    return end - start;
}
/***
 * des scroll 滚动
 * @param :? ref || element
 * @param : 滚动到多少
 * @param :: callback
 * **/

export function scrollMove (ele,num,cb){
    // if(type(ele) !== "object" || type(cb) !== "function"){ return; }

    // let n = 1;
    // if(ele.scrollLeft && ele.scrollLeft >= num){ cb && cb(); break; }
    ele.scrollLeft = num;
}